//
//  MKTChatTextBlockUIView.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2021/7/13.
//  Copyright © 2021 moon. All rights reserved.
//

#import "MKTChatTextBlockUIView.h"

@implementation MKTChatTextBlockUIView
- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.titleView = [[UILabel alloc] init];
        self.titleView.textColor = [UIColor mk_colorWithLight:[UIColor grayColor] dark:[UIColor lightTextColor]];
        self.titleView.font = [UIFont systemFontOfSize:13];
        [self addSubview:self.titleView];
        //
        self.valueView = [[MKTChatLabelValueUIView alloc] init];
        self.valueView.label.font = [UIFont systemFontOfSize:13];
        [self addSubview:self.valueView];
        //
        self.subvalueView = [[MKTChatLabelValueUIView alloc] init];
        self.subvalueView.label.font = [UIFont systemFontOfSize:11];
        self.subvalueView.label.textColor = [UIColor mk_colorWithLight:[UIColor grayColor] dark:[UIColor lightTextColor]];
        [self addSubview:self.subvalueView];
        //
        self.flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[self.titleView,self.valueView,self.subvalueView] constraintParam:(MKUIFlowLayoutConstraintParam_V_T_L) contentInsets:UIEdgeInsetsZero interitemSpacing:5];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect bounds = self.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}
- (CGSize)sizeThatFits:(CGSize)size{
    return [self.flowlayout sizeThatFits:size resizeItems:YES];
}
- (void)reloadData{
    MKTChatTextBlock *textBlock = self.textBlock;
    self.titleView.text = textBlock.title;
    
    self.valueView.labelValue = textBlock.value;
    self.valueView.hidden = textBlock.value==nil;
    [self.valueView reloadData];
    
    self.subvalueView.labelValue = textBlock.subvalue;
    self.subvalueView.hidden = textBlock.subvalue==nil;
    [self.subvalueView reloadData];
}
@end
